package org.example.api.admin;

import cn.dev33.satoken.stp.StpUtil;
import org.example.R.R;
import org.example.entity.dto.*;
import org.example.entity.vo.admin.AddDyTaskDto;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public R login(@RequestBody LoginUserDto dto){
        return userService.login(dto);
    }

    @PostMapping("/logout")
    public R logout(){
        StpUtil.logout();
        return R.success("退出成功");
    }

    @PostMapping("/isLogin")
    public R isLogin(@RequestParam("tokenValue")String tokenValue){
        return userService.isLogin(tokenValue);
    }

    @PostMapping("/add")
    public R add(@RequestBody AddUserDto dto){
        return userService.add(dto);
    }

    @PostMapping("/detail")
    public R userInfo(@RequestParam("id")Long userId){
        return userService.detail(userId);
    }

    @PostMapping("/save")
    public R save(@RequestBody SaveUserDto dto){
        return userService.save(dto);
    }

    @PostMapping("/modify_password")
    public R save(@RequestBody SavePasswordDto dto){
        return userService.updatePassword(dto);
    }

    @PostMapping("/list")
    public R list(){
        return userService.list();
    }
    @PostMapping("/delete")
    public R delete(@RequestParam("id")Long userId){
        return userService.delete(userId);
    }
    @PostMapping("/modifyRole")
    public R delete(@RequestBody ModifyRoleDto dto){
        return userService.modifyRole(dto);
    }
    @PostMapping("/dy_list")
    public R dyList(){
        return userService.dyList();
    }
    @PostMapping("/ass_task")
    public R assDyTask(@RequestBody AddDyTaskDto dto){
        return userService.assTask(dto);
    }
}
